<?php
/**
 * get tree
 * @package    goodsCategory
 * @author     ben
 */
class getTreeAction extends sfAction
{
    public function execute($request)
    {
        //$this->forward404Unless($request->hasParameter('id'));
        if ($this->getRequest()->isXmlHttpRequest())
        {
            sfConfig::set('sf_web_debug', false);            
        }


        $output = '';
        $resultSet = array('items' => array());

        $resultSet["items"] = JsTreeDataHelper::getInstance()->getTree(WacTable::$goodsCategory, 500);
//        $resultSet["items"] = $this->getRequest()->getParameterHolder()->getAll();


//        $resultSet["items"] = array(
//            array("attributes"=>array("id"=>"node_1", "node_value"=>"1"), "data"=>array("title"=>"中文1"), "state"=>"open"),
//            array("attributes"=>array("id"=>"node_2", "node_value"=>"2"),
//                  "data"=>array("title"=>"中文2"),
//                  "children"=>array(
//                      array(
//                        "attributes"=>array("id"=>"node_4", "node_value"=>"4"),
//                        "data"=>array("title"=>"node4"),
//                        "state"=>"open"
//                      ),
//                      array(
//                        "attributes"=>array("id"=>"node_5", "node_value"=>"5"),
//                        "data"=>array("title"=>"node5"),
//                        "state"=>"open"
//                      ),
//                  ),
//                  "state"=>"open"
//                  ),
//            array("attributes"=>array("id"=>"node_3", "node_value"=>"3"), "data"=>array("title"=>"node3"), "state"=>"open"),
//        );
        
        if ($this->getRequest()->isXmlHttpRequest())
        {
            $this->getResponse()->setContentType('application/json; charset=utf-8');
            $output = json_encode($resultSet);
        } 
        else
        {
            $output = print_r($resultSet, true);
        }

        return $this->renderText($output);
    }
}